#!/bin/bash
#功能：导入车辆通信号

#初始化环境变量
source $(cd "$(dirname "$0")"; pwd)/../../initEnv.sh
table_name=ods_hy_car_terminal_temp
target_table_name=ods_hy_car_terminal_temp
echo "导入${target_table_name}开始..."

sqoop-import \
  -D mapred.job.queue.name=hive \
  --connect $HY_CONNECT \
  --username $HY_USERNAME \
  --password $HY_PASSWORD \
  --query 'SELECT
	        c.CHASSIS_NUM AS CHASSIS_NUM,
	        c.car_model_code AS car_model_code,
	        c.CAR_MODEL AS CAR_MODEL,
	        t.T_COMMUNICATION_ID AS terminal_id
           FROM
	            hy_car c
           LEFT JOIN hy_terminal t ON c.CAR_TERMINAL = t.T_ID
           WHERE
	            c.DEL_FLAG = 0
                AND t.DEL_FLAG = 0 or $CONDITIONS' \
  --fields-terminated-by "\0001" \
  --delete-target-dir \
  --target-dir /user/root/mysql_tables/${table_name} \
  --hive-import \
  --hive-overwrite \
  --hive-table ${target_table_name} \
  --hive-database ${HIVE_DB} \
  --hive-drop-import-delims \
  --num-mappers 1 \
  --as-parquetfile;


if [ $? -ne 0 ] ; then
  echo "导入ods_hy_car_terminal_temp失败，耗时$((`date +%s`-START_TIME))秒..."
else
  echo "导入ods_hy_car_terminal_temp成功，耗时$((`date +%s`-START_TIME))秒..."
fi
